home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / SWAG9605.DDD / 0053_Opening Locked-Protected files.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-05-31  |  1.8 KB  |  42 lines

  1. (*
  2. MH│Anyone have any suggestions on protecting source code against this sort
  3.   │of piracy? I have tried using a CRC calculation on the .EXE but run
  4.   │into "FILE ACCESS DENIED" if the game is running on a network (the
  5.   │program is meant for networks...)
  6. MH│Any suggestions would be appreciated.
  7.  
  8.  You are probably opening the .exe file with RESET command using the
  9.  default file open mode of read/write which tries to open it with
  10.  read/write access privileges.  Normal access to network programs is
  11.  probably set to read-only access.  Below is how I open a binary file in
  12.  read-only mode in Turbo Pascal v6.  The filemode variable is located in
  13.  the TP system unit. 0=read/only 1=write/only 2=read/write 64=shared-r/o
  14.  65=shared-w/o 66=shared-r/w.  In your case there may be no need to test
  15.  the file attribute first, as the r/o attribute may not be set. But you
  16.  could attempt to always open it with file mode 2 and then try mode 0 or
  17.  64 if mode 2 wasn't successful. Remember to set the file mode back to
  18.  'normal' before opening normal r/w files.
  19.  *)
  20.  
  21.  Function  OpenF(name:pathstr):boolean;
  22.      var
  23.        readonly : boolean;
  24.        goodfile : boolean;
  25.        attrword  : word;
  26.    begin
  27.      Assign(f,name);  { f is global untyped file ie.  var f:file; }
  28.      GetFAttr(f,attrword);
  29.      readonly := odd(attrword);  { if file read-only attribute is set }
  30.      if readonly then
  31.        filemode := 0   { allows open of untyped file r/o }
  32.       else
  33.        filemode := 2;  { normal readwrite untyped file }
  34.      {$I-}
  35.      Reset(f,1);   { recordsize = 1 byte }
  36.      {$I+}
  37.      goodfile := (ioresult = 0);
  38.      if goodfile then goodfile := (not eof(f));  {protect against
  39.                                                   0 byte files}
  40.      OpenF := goodfile;
  41.    end; {openf}
  42.